package controller;

import document.HtmlDocument;

import java.util.ArrayList;


/**
 * Created by Pavel Nikolaev
 */
public class DocumentHistory {
    private ArrayList<HtmlDocument> myHistory;
    private int myCurrentDocumentIndex;
    //private LinkedList<HtmlDocument> myHistory;
    //private Iterator<HtmlDocument> myCurrentDocumentIterator;


    public DocumentHistory() {
        this.myHistory = new ArrayList<HtmlDocument>();
        myCurrentDocumentIndex = -1;
    }

    public void add(HtmlDocument document) {
        myCurrentDocumentIndex++;
        for (int i = myHistory.size() - 1; i >= myCurrentDocumentIndex; --i)
            myHistory.remove(i);
        myHistory.add(document);
    }

    public boolean goForward() {
        return (++myCurrentDocumentIndex < myHistory.size() - 1);
    }

    public boolean goBack() {
        return (--myCurrentDocumentIndex > 0);
    }

    public HtmlDocument getDocument() {
        return myHistory.get(myCurrentDocumentIndex);
    }

    public boolean isBackwardStepAvailable() {
        return (myCurrentDocumentIndex > 0);
    }
}
